package com.diliuzun.delivery.mapper;

import com.diliuzun.delivery.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.ArrayList;

@Repository
public interface UserMapper {
    @Insert("insert into user(yhbh,yhm,pwd,yhnc,yhsf,yhtx,sex,sjh,email,zcsj) values(#{yhbh},#{yhm},#{pwd},#{yhnc},#{yhsf},#{yhtx},#{sex},#{sjh},#{email},now())")
    int addUser(User user);

    @UpdateProvider(type = UserMapperProvider.class, method = "getUpdateUserSql")
    int updateUser(User user);

    @Delete("delete from user where yhbh=#{id}")
    int deleteUserById(Serializable id);

    @Select("select yhbh,yhm,pwd,yhnc,yhsf,sex,yhtx,sjh,email,zcsj from user where yhbh=#{id}")
    User selectUserById(Serializable id);

    @Select("select * from user where yhm=#{yhm} and pwd = #{pwd}")
    User selectUser(User user);

    @SelectProvider(type = UserMapperProvider.class, method = "getSelectUsersSql")
    ArrayList<User> selectUsers(User user);


    //--------------------------------------------------------------------------
    @Update("update user set yhm=#{yhm} where yhbh=#{yhbh}")
    int updateYhmById(User user);

    @Select("select * from user where yhm=#{param2} and pwd=#{param1}")
    User selectUserByYhmAndPwd(String pwd,String yhm);

    @Select("select * from user where yhm=#{param1.yhm} and pwd=#{param2.pwd}")
    ArrayList<User> selectUsersByUser(User user1,User user2);

    @SelectProvider(type = UserMapperProvider.class, method = "getSelectUsersByUser2Sql")
    ArrayList<User> selectUsersByUser2(User user1,User user2);
}
